/**
 * @param {number[][]} mat
 * @return {number}
 */
export var diagonalSum = function (mat) {
  let sum = 0
  const n = mat.length
  let i = 0
  while (i < n) {
    sum += mat[i][i] + (n - 1 - i !== i ? mat[i][n - 1 - i] : 0)
    i++
  }
  return sum
}

/**
 * 优化速度
 * @param {number[][]} mat
 * @return {number}
 */
export var diagonalSum2 = function (mat) {
  let sum = 0
  let i = 0
  while (i < mat.length) {
    sum += mat[i][i] + mat[i][mat.length - 1 - i]
    i++
  }
  return sum - mat[mat.length >> 1][mat.length >> 1] * (mat.length & 1)
}
